//
//  BookNameView.swift
//  KoiAccounting
//
//  Created by 纪洪文 on 26.03.25.
//

import SwiftUI

struct BookNameView: View {
    
    var book: AccountingBook
    var style: BookNameViewStyle = .small
    
    var body: some View {
        HStack {
            ZStack {
                Image("koi_ic_wallet_highlight")
                    .renderingMode(.template)
                    .resizable().frame(width: bookIconHighlightSize(), height: bookIconHighlightSize())
                    .foregroundColor(book.getBookColor())
                Image("koi_ic_wallet").resizable().frame(width: bookIconSize(), height: bookIconSize())
            }
            Text(book.bookName.orEmpty)
                .font(.system(size: bookNameSize()))
                .fontWeight(bookNameFontWeight())
                .foregroundColor(Color.koiColorTitle)
        }
    }
    
    private func bookNameFontWeight() -> Font.Weight {
        switch style {
        case .large:
            return Font.Weight.bold
        case .small:
            return Font.Weight.regular
        }
    }
    
    private func bookNameSize() -> CGFloat {
        switch style {
        case .large:
            return 16
        case .small:
            return 14
        }
    }
    private func bookIconSize() -> CGFloat {
        switch style {
        case .large:
            return 24
        case .small:
            return 20
        }
    }
    private func bookIconHighlightSize() -> CGFloat {
        switch style {
        case .large:
            return 16
        case .small:
            return 12
        }
    }
}

enum BookNameViewStyle {
    case small, large
}

@available(iOS 18.0, *)
#Preview {
    @Previewable @State var book:AccountingBook = AccountingBook(bookName : "默认账本")
    BookNameView(book: book)
}
